package microcredit.gui.table.impl;

import java.awt.Color;
import java.util.Date;

import javax.swing.ImageIcon;

import microcredit.gui.table.EnumBeanTableModel;
import microcredit.gui.util.FormatUtilities;
import microcredit.model.Member;
import microcredit.model.MemberStatusHistory;
import microcredit.model.MemberToTrainingType;
import microcredit.model.domain.TrainingStatus;

enum MemberToTrainingAssignmentColumn {
	COLUMN_MEMBER_NUMBER,
	COLUMN_MEMBER,
	COLUMN_STATUS,
	COLUMN_MEMBER_DATE,
}
public class MemberToTrainingAssignmentTableModel extends EnumBeanTableModel<MemberToTrainingType, MemberToTrainingAssignmentColumn> {

	@Override
	protected Object getValue(MemberToTrainingType o,
			MemberToTrainingAssignmentColumn column) {
		switch (column) {
		case COLUMN_MEMBER : return o.getMember().getFullName();
		case COLUMN_MEMBER_DATE : return o.getDate();
		case COLUMN_STATUS : return o.getStatus() != null ? o.getStatus().getDisplayName() : " - ";
		case COLUMN_MEMBER_NUMBER : return Member.formatID(o.getMember().getId());
		}
		return null;
	}
	
	@Override
	protected Class<?> getValueClass(MemberToTrainingAssignmentColumn column) {
		switch (column) {
		case COLUMN_MEMBER_DATE : return Date.class;
		}
		return super.getValueClass(column);
	}
	
	@Override
	protected Object getFormat(MemberToTrainingType o,
			MemberToTrainingAssignmentColumn column) {
		switch (column) {
		case COLUMN_MEMBER_DATE : return FormatUtilities.getDateFormat();
		}
		return super.getFormat(o, column);
	}

	@Override
	protected String getName(MemberToTrainingAssignmentColumn column) {
		switch (column) {
		case COLUMN_MEMBER_NUMBER : return "No";
		case COLUMN_MEMBER : return "Member";
		case COLUMN_STATUS : return "Status";
		case COLUMN_MEMBER_DATE : return "Date";
		}
		return null;
	} 
	
	@Override
	protected int getWidth(MemberToTrainingAssignmentColumn column) {
		switch (column) {
		case COLUMN_MEMBER_NUMBER : return 50;
		case COLUMN_MEMBER : return 200;
		case COLUMN_STATUS : return 100;
		case COLUMN_MEMBER_DATE : return 100;
		}
		return -1;
	}
	
	@Override
	protected MemberToTrainingAssignmentColumn getSortColumn() {
		return MemberToTrainingAssignmentColumn.COLUMN_MEMBER;
	}
	
	@Override
	public ImageIcon getRowIcon() {
		return new ImageIcon(MemberStatusHistory.class
				.getResource("/microcredit/icons/x16/id_card.png"));
	}
	
	@Override
	protected Color getForeground(MemberToTrainingType o,
			MemberToTrainingAssignmentColumn column) {
		if (o.getStatus() != null) {
			if (o.getStatus() == TrainingStatus.P) {
				return Color.BLUE;
			} else if (o.getStatus() == TrainingStatus.M) {
				return Color.RED;
			}
		}
		return null;
	}
	


}
